package com.need3

import com.typesafe.config.ConfigFactory
import org.apache.commons.pool2.impl.GenericObjectPoolConfig
import redis.clients.jedis.{Jedis, JedisPool}

/**
  * Created by zhuang on 2018/3/4.
  */
object GetRedis {
  private lazy val load = ConfigFactory.load()
  private val poolConfig = new GenericObjectPoolConfig()
  private lazy val pool = new JedisPool(
    poolConfig,
    load.getString("redis.host"),
    load.getInt("redis.port"),
    3000,
    null, //密码
    7 //设置数据储存在redis的几号库
  )

  def getRedis(): Jedis = {
    //拿到 一个连接实例
    pool.getResource
  }
}
